package com.coffee.admin.controller.supplier;

import com.alibaba.fastjson.JSONObject;
import com.coffee.admin.api.common.req.AdminMenuRequest;
import com.coffee.admin.api.common.result.CommonMenuResult;
import com.coffee.admin.api.common.service.AdminMenuService;
import com.coffee.admin.controller.BaseController;
import com.coffee.core.anotation.OperLog;
import com.coffee.core.entity.LoginUser;
import com.coffee.core.exception.BusinessException;
import com.coffee.core.result.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 后台菜单
 * @Author liaoyangfan
 * @Date 2021/3/23 15:42
 * @Version 1.0
 **/
@RestController
@RequestMapping("/menu")
public class SupplierMenuController extends BaseController {
    private final static Logger logger = LoggerFactory.getLogger(SupplierMenuController.class);

    @DubboReference(check = false)
    private AdminMenuService menuService;

    @OperLog(operModul = "菜单管理", operDesc = "菜单列表")
    @PostMapping("/list")
    public Result<CommonMenuResult> list() {
        AdminMenuRequest request = new AdminMenuRequest();
        LoginUser supplier = getSupplier();
        logger.info("supplier===" + JSONObject.toJSONString(supplier));
        if (supplier.getSupplierUserId() != null) {
            request.setSupplierIsAdmin(supplier.getSupplierIsAdmin());
            request.setSupplierUserId(supplier.getSupplierUserId());
            request.setSupplierId(supplier.getSupplierId());
        }
        if (supplier.getPlatformUserId() != null) {
            request.setPlatformUserId(supplier.getPlatformUserId());
            request.setPlatformIsAdmin(supplier.getPlatformIsAdmin());
        }
        CommonMenuResult result = null;
        try {
            result = menuService.supplierList(request);
        } catch (BusinessException e) {
            e.printStackTrace();
            return Result.failed(e.getCode(), e.getMessage());
        }
        return Result.success(result);

    }


}
